// 导入express模块
const express = require('express')
// 创建应用
const app = express()

function cookieParser() {
    return function (req, res, next) {
        req.cookies = {}
        const headerCookie = req.headers.cookie
        if (headerCookie) {
            const cookies = headerCookie.split(';')
            cookies.forEach(cookie => {
                const pairs = cookie.split('=')
                req.cookies[pairs[0]] = pairs[1]
            });
        }
        next()
    }
}

app.get('/', cookieParser(), (req, res) => {
    res.send(req.cookies)
})

app.listen(8899, () => {
    console.log('listen on 8899');
})